package se.jocke.nb.proxy.ui.node;

import java.util.LinkedHashSet;
import java.util.Set;
import org.openide.nodes.Children;
import org.openide.nodes.Node;
import se.jocke.nb.proxy.monitor.model.HttpMessage;

/**
 *
 * @author jocke
 */
public class HttpMessageChildren extends Children.Keys {

    private final Set<HttpMessage> messages;

    public HttpMessageChildren() {
        this.messages = new LinkedHashSet<HttpMessage>();
    }

    public void add(HttpMessage e) {
        messages.remove(e);
        addNotify();
        messages.add(e);
        addNotify();
    }

    public void remove(HttpMessage o) {
        messages.remove(o);
        addNotify();
    }

    public void clear() {
        messages.clear();
        addNotify();
    }

    @Override
    protected Node[] createNodes(Object key) {
        HttpMessage message = (HttpMessage) key;
        return new Node[]{new HttpMessageNode(message)};
    }

    @Override
    protected void addNotify() {
        super.addNotify();
        setKeys(messages);
    }

}
